#include <bits/stdc++.h>

using namespace std;
// ofstream output("out.out");

typedef struct Node
{
    int val;
    Node *left;
    Node *right;
    Node() : val(0), left(nullptr), right(nullptr) {}
    Node(int x) : val(x), left(nullptr), right(nullptr) {}
    Node(int x, Node *left, Node *right) : val(x), left(left), right(right) {}
} *PNode;
void helperPrint(PNode root)
{
    if (root == nullptr)
    {
        return;
    }
    cout << root->val << " ";
    helperPrint(root->left);
    helperPrint(root->right);
}
class Solution
{
public:
    PNode buildTree(vector<int> &inorder, vector<int> &postorder)
    {
        if (postorder.size() == 0)
        {
            return nullptr;
        }
        PNode root = new Node(postorder[postorder.size() - 1]);
        stack<PNode> s_t;
        s_t.push(root);
        int inorder_idx = inorder.size() - 1;
        for (int i = int(postorder.size()) - 2; i >= 0; i--)
        {
            int postorder_val = postorder[i];
            PNode node = s_t.top();
            if (node->val != inorder[inorder_idx])
            {
                node->right = new Node(postorder_val);
                s_t.push(node->right);
            }
            else
            {
                while (!s_t.empty() && s_t.top()->val == inorder[inorder_idx])
                {
                    node = s_t.top();
                    s_t.pop();
                    inorder_idx--;
                }
                node->left = new Node(postorder_val);
                s_t.push(node->left);
            }
        }
        return root;
    }
};

int main()
{
    vector<int> inorder, postorder;

    string readed;
    int num;

    getline(cin, readed);
    stringstream readedstream1(readed);
    while (readedstream1 >> num)
    {
        inorder.push_back(num);
    }

    getline(cin, readed);
    stringstream readedstream2(readed);
    while (readedstream2 >> num)
    {
        postorder.push_back(num);
    }

    helperPrint(Solution().buildTree(inorder, postorder));
    // output.close();

    // system("pause");
    return 0;
}